import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import javax.swing.event.*;
import java.lang.reflect.*;
import java.net.*;


class Login extends JFrame
	{
        Container contain;
        JPasswordField password;
        JTextField text1;
        JButton button1,button2,button3,button4;
        JLabel label1,label2,label3;
        JPanel panel1,panel2,panel3;
        String line;
        String name = "";
        String id = "";
        String code = "";
        String username = "";
        String pass = "";

		Login(){
		super("Instructor Login ");


		contain=getContentPane();
		contain.setLayout(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		panel1=new JPanel(null,true);
		label1=new JLabel("User Name");
		label1.setForeground(Color.black);
		label1.setBounds(10,10,120,25);
		panel1.add(label1);

		text1=new JTextField();
		text1.setEditable(true);
		text1.setBounds(100,10,120,25);
		panel1.add(text1);

		label2=new JLabel("Password");
		label2.setForeground(Color.black);
		label2.setBounds(10,50,120,25);
		panel1.add(label2);

		password=new JPasswordField();
		password.setBounds(100,50,120,25);
		panel1.add(password);

		label3=new JLabel();
		label3.setBounds(15,125,260,25);
		panel1.add(label3);

		button1=new JButton("Ok");
		button1.setBounds(20,90,100,25);
		panel1.add(button1);

		button2=new JButton("Create");
		button2.setBounds(130,90,100,25);
		panel1.add(button2);

		button3=new JButton("Back");
		button3.setBounds(0,116,100,25);
		panel1.add(button3);

		button4 = new JButton("Clear");
		button4.setBounds(130,116,100,25);
		panel1.add(button4);

		Color r3=new Color(122,145,201);

		panel1.setBounds(0,0,260,260);
		contain.add(panel1);

        try {
            BufferedReader br = new BufferedReader(new FileReader("InstructorRecords.txt"));
            while ( ( line = br.readLine() ) != null ) {
                String [] tmp = line.split(",");
                name = tmp[0];
                id = tmp[1];
				code = tmp[2];
                username = tmp[3];
                pass = tmp[4];
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
		
        button1.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
				if(text1.getText().equalsIgnoreCase(username) && password.getText().equals(pass)){
						StudentMainClass studProg=new StudentMainClass();
						try {
						studProg.run();
							setVisible(false);
							studProg.setVisible(false);
							studProg.setSize(800,600);
						} catch (Exception err) {
							err.printStackTrace();
						}

				}else{
						label3.setText("Please Check Username and Password");
						label3.setForeground(Color.red);
						}
				}
        });

        button2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				Create create = new Create();
				try {
				//        create.run();
					setVisible(false);
					create.setVisible(false);
					create.setSize(800,600);
					}catch (Exception err) {
						err.printStackTrace();
					}
						
			}
		});
        
		button3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				try{
				MemberType s=new MemberType();

				s.setVisible(true);
				s.setSize(270,180);
				dispose();
				s.setLocation(500,250);
				}catch(Exception sam){
					
				}
			}
		});
   
		button4.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				text1.setText("");
				password.setText("");
			}
		});
		
		
		text1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
							
				if(text1.getText().equalsIgnoreCase(username) && password.getText().equals(pass)){
					String message = username + pass;
					StudentMainClass studProg=new StudentMainClass();
					if (message.isEmpty()){
						return;
					}
					try {
						studProg.run();
						setVisible(false);
						studProg.setVisible(false);
						studProg.setSize(800,600);
					} catch (Exception err) {
						err.printStackTrace();
					}
				}
				label3.setText("Please Check Username and Password");
				label3.setForeground(Color.red);
			}
		});
		
		password.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
						
				if(text1.getText().equalsIgnoreCase(username) && password.getText().equals(pass)){
					String message = username + pass;
					StudentMainClass studProg=new StudentMainClass();
					if (message.isEmpty()){
						return;
						}
                        try {
							studProg.run();
                            setVisible(false);
                            studProg.setVisible(false);
                            studProg.setSize(800,600);
                        } catch (Exception err) {
                            err.printStackTrace();
                        }
					}	
				label3.setText("Please Check Username and Password");
                label3.setForeground(Color.red);
			}
        });
		
        
}
}
